package cn.wuxing.mediation.web.controller.duty;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.wuxing.mediation.system.domain.LeadDutyArrangement;
import cn.wuxing.mediation.system.domain.VisitingReception;
import cn.wuxing.mediation.system.domain.vo.LeadVo;
import cn.wuxing.mediation.system.domain.vo.VisitingVo;
import cn.wuxing.mediation.system.service.ILeadDutyArrangementService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.wuxing.mediation.common.annotation.Log;
import cn.wuxing.mediation.common.core.controller.BaseController;
import cn.wuxing.mediation.common.core.domain.AjaxResult;
import cn.wuxing.mediation.common.enums.BusinessType;
import cn.wuxing.mediation.common.utils.poi.ExcelUtil;
import cn.wuxing.mediation.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 领导值班安排Controller
 *
 * @author mediation
 * @date 2024-10-12
 */
@RestController
@RequestMapping("/system/arrangement")
public class LeadDutyArrangementController extends BaseController
{
    @Resource
    private ILeadDutyArrangementService leadDutyArrangementService;

    /**
     * 查询领导值班安排列表
     */
    @PreAuthorize("@ss.hasPermi('system:arrangement:list')")
    @GetMapping("/list")
    public TableDataInfo list(LeadDutyArrangement leadDutyArrangement)
    {
        startPage();
        List<LeadDutyArrangement> list = leadDutyArrangementService.selectLeadDutyArrangementList(leadDutyArrangement);
        return getDataTable(list);
    }

    /**
     * 导出领导值班安排列表
     */
    @PreAuthorize("@ss.hasPermi('system:arrangement:export')")
    @Log(title = "领导值班安排", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LeadDutyArrangement leadDutyArrangement)
    {
        List<LeadDutyArrangement> list = leadDutyArrangementService.selectLeadDutyArrangementList(leadDutyArrangement);
        ExcelUtil<LeadDutyArrangement> util = new ExcelUtil<LeadDutyArrangement>(LeadDutyArrangement.class);
        util.exportExcel(response, list, "领导值班安排数据");
    }

    /**
     * 获取领导值班安排详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:arrangement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(leadDutyArrangementService.selectLeadDutyArrangementById(id));
    }

    /**
     * 新增领导值班安排
     */
    @PreAuthorize("@ss.hasPermi('system:arrangement:add')")
    @Log(title = "领导值班安排", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LeadDutyArrangement leadDutyArrangement)
    {
        return toAjax(leadDutyArrangementService.insertLeadDutyArrangement(leadDutyArrangement));
    }

    /**
     * 修改领导值班安排
     */
    @PreAuthorize("@ss.hasPermi('system:arrangement:edit')")
    @Log(title = "领导值班安排", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LeadDutyArrangement leadDutyArrangement)
    {
        return toAjax(leadDutyArrangementService.updateLeadDutyArrangement(leadDutyArrangement));
    }

    /**
     * 删除领导值班安排
     */
    @PreAuthorize("@ss.hasPermi('system:arrangement:remove')")
    @Log(title = "领导值班安排", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(leadDutyArrangementService.deleteLeadDutyArrangementByIds(ids));
    }

    /**
     * 下载导入模板
     *
     * @param response
     */
    @PostMapping("/exportTemplate")
    public void exportTemplate(HttpServletResponse response) {
        ExcelUtil<LeadVo> util = new ExcelUtil<LeadVo>(LeadVo.class);
        util.importTemplateExcel(response, "领导值班");
    }

    /**
     * 导入
     *
     * @param file
     * @param updateSupport
     * @return
     * @throws Exception
     */
    @PreAuthorize("@ss.hasPermi('system:scheduling:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<LeadDutyArrangement> util = new ExcelUtil<LeadDutyArrangement>(LeadDutyArrangement.class);
        List<LeadDutyArrangement> leadDutyArrangementList = util.importExcel(file.getInputStream());
        String message = leadDutyArrangementService.importShiftScheduling(leadDutyArrangementList, updateSupport);
        return success(message);
    }
}
